package br.com.lh.urabuilder.command
{
	import br.com.lh.urabuilder.domain.view.UraResource;
	import br.com.lh.urabuilder.event.LoadUraResourceEvent;
	import br.com.lh.urabuilder.model.UraModelLocator;
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;

	public class LoadUraResourcesCommand implements ICommand
	{
		private var modelLocator:UraModelLocator =  UraModelLocator.getInstance();
		
		public function LoadUraResourcesCommand(){
		}

		public function execute(event:CairngormEvent):void{
			var dbServer:RemoteObject = new RemoteObject("dbDestination");
			var sessionId:String = LoadUraResourceEvent(event).sessionId;
			dbServer.getUraResource(sessionId);
			dbServer.getUraResource.addEventListener("result",doLoad);	
		}
		
		private function doLoad(event:ResultEvent):void	{
			if (event.result == null){
				return;
			}
			var uraResource:UraResource = UraResource(event.result);
			modelLocator.resourceManager.availableExtension = uraResource.availableExtension;
			modelLocator.resourceManager.soundList = uraResource.soundFileList;
		}
		
	}
}